import java.util.PriorityQueue;

public class Test2 {

    //最小的k个数(top排序)

    //大根堆(需要比较器)
    public int[] samllestk(int[] arr,int k){
        PriorityQueue<Integer> priorityQueue =new PriorityQueue<>(k,new Imp());
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }

        for (int i = k; i < arr.length; i++) {
            //遍历剩下的元素
            int t = priorityQueue.peek();
            if(arr[i]<t){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }
        int[] tmp = new int[k];
        for (int i = 0; i < k; i++) {
            tmp[i] = priorityQueue.poll();
        }
        return tmp;

    }




    //小根堆
    public int[] samllestk1(int[] arr,int k){
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(arr.length);
        for (int i = 0; i < arr.length; i++) {
            priorityQueue.offer(arr[i]);//在小根堆中存放好数据
        }
        int[] tmp = new int[k];
        for (int i = 0; i < k; i++) {
            tmp[i] = priorityQueue.poll();
        }
        return tmp;
    }




    public static void main1(String[] args) {
        Person person1 = new Person(12,"lisi");
        Person person2 = new Person(19,"zhangsan");
        System.out.println(person1.compareTo(person2));
    }
}
